package processingdata.weather;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

import processing.core.PVector;
import Control.WeatherStation;

public class WeatherSerializer {

	static ArrayList<WeatherStation> stations=new ArrayList<WeatherStation>();
	public static void main(String args[]) throws Exception, IOException
	{

		BufferedReader inputReader=new BufferedReader(new FileReader(new File("data/weather.data")));
		while(inputReader.ready())
		{
			String inputLine=inputReader.readLine();
			String inputLineParts[]=inputLine.split("\t");
			String name=inputLineParts[0];
			String state=inputLineParts[1];
			float latitude=Float.parseFloat(inputLineParts[2]);
			float longitude=Float.parseFloat(inputLineParts[3]);
			String country=inputLineParts[4];
			PVector coordinates=new PVector(latitude, longitude);
			WeatherStation weatherStation=new WeatherStation();
			weatherStation.setCoordinates(coordinates);
			weatherStation.setCountry(country);
			weatherStation.setState(state);
			weatherStation.setName(name);
			stations.add(weatherStation);
		}
		serializeStations();
	}
	
	static void serializeStations() throws FileNotFoundException, IOException
	{
		ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream(new File("data/stations.ser")));
		oos.writeObject(stations);
		oos.close();
	}

}
